﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoadTeam.Standard;
using RoadTeam.BLL;
using System.Data;

namespace RoadTeam.Pase
{
    public class PaseUnit : BasePase
    {
        #region 根据机构标识获取单元信息[GetUnitData]
        /// <summary>
        /// 根据机构标识获取单元信息
        /// 参数[OrganIdentifier]:机构标识
        /// </summary>
        /// <param name="OrganIdentifier">机构标识</param>
        /// <returns>单元信息</returns>
        public static RmUnit GetUnitData(String OrganIdentifier)
        {

            BllBase bllbase = new BllBase();
            //bllbase.InserLog("方法名[GetUnitData]调用时间[" + DateTime.Now.ToString() + "]参数:[" + OrganIdentifier + "]");
            bllbase.InsertLog("方法名[GetUnitData]调用时间[" + DateTime.Now.ToString() + "]参数为:[" + OrganIdentifier + "]",
@"RoadTeam.Pase.PaseUnit", "public static RmUnit GetUnitData(String OrganIdentifier)");

            RmUnitBll bll = new RmUnitBll();
            DataTable dt = bll.GetUnitTable(OrganIdentifier);
            List<Unit> li = DtToList<Unit>(dt);
            RmUnit Unit = new RmUnit();
            Unit.Item = li.ToArray();
            return Unit;
        }
        #endregion

        #region 根据分页信息获取单元信息[GetUnitDataByPage]
        public static RmUnit2 GetUnitDataByPage(String OrganIdentifier, int CurrentPage, int PageSize)
        {

            BllBase bllbase = new BllBase();
            bllbase.InsertLog("方法名[GetUnitDataByPage]调用时间[" + DateTime.Now.ToString() + "]参数为:[" + OrganIdentifier + "][" + CurrentPage + "][" + PageSize + "]",
@"RoadTeam.Pase.PaseUnit", "public static RmUnit2 GetUnitDataByPage(String OrganIdentifier, int CurrentPage, int PageSize)");


            RmUnit2Bll bll = new RmUnit2Bll();
            RmCustBll bllcust = new RmCustBll();
            DataTable dt_Unit = bll.GetUnitData(OrganIdentifier, CurrentPage, PageSize);//获取单元数据
            DataTable dt_Cust = bllcust.SyncCustData(dt_Unit);//获取客户数据
            List<Unit2> li = DtToList<Unit2>(dt_Unit);
            DataRow[] drs;
            DataTable dt_Temp;
            List<Cust> li_Cust;
            foreach (Unit2 Unit in li)
            {
                drs = dt_Cust.Select(@"UnitIdentifier='" + Unit.UnitIdentifier + "'");
                if (drs.Count() == 0) continue;
                dt_Temp = RoadTeam.Pub.ConverTable.ToDataTable(drs);
                li_Cust = DtToList<Cust>(dt_Temp);
                Unit.Item = li_Cust.ToArray();
            }
            RmUnit2 Unit2 = new RmUnit2();
            Unit2.Item = li.ToArray();
            return Unit2;

        }       
        #endregion

        #region 获取单元总页数[GetUnitAllPageCount]
        public static int GetUnitAllPageCount(String OrganIdentifier)
        {
            BllBase bllbase = new BllBase();
            bllbase.InsertLog("方法名[GetUnitAllPageCount]调用时间[" + DateTime.Now.ToString() + "]参数为:[" + OrganIdentifier + "]",
@"RoadTeam.Pase.PaseUnit", "public static int GetUnitAllPageCount(String OrganIdentifier)");

            RmUnit2Bll bll = new RmUnit2Bll();
            return bll.GetUnitAllPageCount(OrganIdentifier);
        }

         #endregion
    }
}
